// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 1005;

int a[N][N];

int t, n;


int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &t);
    // dbg(t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%d", &n);
        for (int i=0; i<n; ++i)
            for (int j=0; j<n; ++j) {
                scanf("%d", &a[i][j]);
            }

        int trace = 0;
        for (int i=0; i<n; ++i)
            trace += a[i][i];
        int nr = 0, nc = 0;
        for (int i=0; i<n; ++i) {
            static bool vis[N];
            for (int j=0; j<n; ++j) {
                if (vis[a[i][j]]) {
                    ++nr;
                    break;
                } else
                    vis[a[i][j]] = 1;
            }
            for (int j=0; j<n; ++j)
                vis[a[i][j]] = 0;
        }

        for (int i=0; i<n; ++i) {
            static bool vis[N];
            for (int j=0; j<n; ++j) {
                if (vis[a[j][i]]) {
                    ++nc;
                    break;
                } else
                    vis[a[j][i]] = 1;
            }
            for (int j=0; j<n; ++j)
                vis[a[j][i]] = 0;
        }
        printf("Case #%d: %d %d %d\n", kk+1, trace, nr, nc);
    }
    return 0;
}
